home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / tutorial / tutorial.lha / et++-tutorial / lern3 / beisp / hello2.C < prev    next >
C/C++ Source or Header  |  1992-01-24  |  3KB  |  120 lines

  1. //
  2. // E++ Tutorial  Lernabschnitt: 1   Beispiel: 2   hello2
  3. //
  4. //
  5. // Hello world with ET++:
  6. // - the string "hello world" is shown in a scrollable window
  7. // - the current layout can be loaded from a file
  8. //
  9.  
  10. #ifdef ET_DUMP
  11. #include "ET_Dump.h"
  12. #endif
  13.  
  14. #include "ET++.h"
  15. #include "Collection.h"
  16.  
  17. //---- HelloView -------------------------------------------------------------------
  18.  
  19. class HelloView: public View { 
  20.     TextItem *viewtext;
  21. public:
  22.     MetaDef(HelloView);
  23.     HelloView(Document *dp, Rectangle itsExtent) : View(dp, itsExtent)
  24.     { }
  25.     void Draw(Rectangle r);
  26.     void SetText(TextItem *t);
  27. };
  28.  
  29. MetaImpl(HelloView, (TP(viewtext)));
  30.         
  31. void HelloView::SetText(TextItem *t)
  32. {
  33.     viewtext = t;
  34.     // force the the text item to calculate its extent 
  35.     viewtext->CalcExtent(); 
  36.     // install the text item in this view
  37.     viewtext->SetContainer(this);
  38.     ForceRedraw();
  39. }
  40.  
  41. void HelloView::Draw(Rectangle r)
  42.     viewtext->DrawAll(r); 
  43. }
  44.  
  45.  
  46.  
  47. //---- HelloDocument ---------------------------------------------------------------
  48.  
  49. class HelloDocument : public Document {
  50.     HelloView *view;
  51.     TextItem *text;
  52. public:
  53.     MetaDef(HelloDocument);
  54.     HelloDocument();
  55.     ~HelloDocument();
  56.     Window *DoMakeWindows();
  57.     void DoRead(istream &, class FileType *);
  58.     void DoWrite(ostream &, int);
  59. };
  60.  
  61. MetaImpl(HelloDocument, (TP(view), TP(text)));
  62.  
  63. HelloDocument::HelloDocument() : Document("HELLO")
  64. {
  65.     static int family= 1;
  66.  
  67.     family= (family+1) % 10;  // cycle through first 10 font families 
  68.     text= new TextItem("hello world             ",
  69.         new_Font(GrFont(family), 24, GrFace(eFaceBold|eFaceShadow))); 
  70.     text->SetOrigin(Point(50));
  71. }
  72.  
  73. HelloDocument::~HelloDocument()
  74. {
  75.     SafeDelete(view);
  76.     SafeDelete(text);
  77. }
  78.  
  79. Window *HelloDocument::DoMakeWindows()
  80. {
  81.     view= new HelloView(this, Point(400));
  82.     view->SetText(text);
  83.     return new Window(this, Point(250), eWinDefault, new Scroller(view));
  84.  }
  85.  
  86. void HelloDocument::DoRead(istream &is, class FileType *ft)
  87. {
  88.     Document::DoRead(is, ft);    // read file type information
  89.     SafeDelete(text);
  90.     is >> text;
  91.     view->SetText(text);
  92. }
  93.  
  94. void HelloDocument::DoWrite(ostream &os, int flag)
  95. {
  96.     Document::DoWrite(os, flag);  // store file type information
  97.     os << text;
  98. }
  99.  
  100. //---- HelloApplication -------------------------------------------------------------------
  101.  
  102. class HelloApplication: public Application {
  103. public:
  104.     MetaDef(HelloApplication);
  105.     HelloApplication(int argc, char **argv) : Application(argc, argv, "HELLO")
  106.     { ApplInit(); }
  107.     Document *DoMakeDocuments(Symbol)
  108.     { return new HelloDocument; }
  109. };
  110.  
  111. MetaImpl0(HelloApplication);
  112.  
  113. //---- main --------------------------------------------------------------------
  114.  
  115. main(int argc, char **argv)
  116. {
  117.     return HelloApplication(argc, argv).Run();
  118. }
  119.